<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
  <head>
    <base href="<%=basePath%>">  
    <title>My JSP 'Sqrt.jsp' starting page</title>
    
  </head>
  <body>  
  	<p>请输入一个正数</p>
    <p>请输入一个数字：</p>
   <%
    	String ret=request.getParameter("num");
  		double n=0.0;
  		try{
  			if(ret!=null){
  				n=Double.parseDouble(ret);
  			}
  		}catch(Exception e){
  				out.println("只能输入正数");
  		}
  %> 
  	<form action="Sqrt.jsp" method="post">
    	<input type="text" name="num" size="15">
    	<input type="submit" value="开始计算"> 	
    </form>	
 
  <p><%=n%>的平方根为<%=Math.sqrt(n)%></p>
  </body>
</html>
